unit uLM2576Rev;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uBaseCalcForm, ExtCtrls, StdCtrls;

type
  TfmLM2576Rev = class(TfmBaseCalcForm)
    edR2: TLabeledEdit;
    edR1: TLabeledEdit;
    laR1: TLabel;
    laR2: TLabel;
    edResult: TLabeledEdit;
    laResult: TLabel;
    Bevel1: TBevel;
    procedure edR1Change(Sender: TObject);
    procedure edR1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  protected
    function DoCheckFields: boolean; override;
    procedure FieldsChanged; override;
  public
    { Public declarations }
    procedure AfterConstruction; override;
  end;

var
  fmLM2576Rev: TfmLM2576Rev;

implementation

{$R *.dfm}

uses uLocalization;

procedure TfmLM2576Rev.AfterConstruction;
begin
  inherited;
  Caption := GetString('#lm2576\revcalc_t');
  SetLabels('R1','R1', GetString('#global\ohm'));
  SetLabels('R2','R2', GetString('#global\ohm'));
  SetLabels('Result', GetString('#global\uout'), GetString('#global\volt'));
end;

function TfmLM2576Rev.DoCheckFields: boolean;
begin
  Result := CheckFieldRange(edR1, 1000, 5100, true) and CheckFieldMore(edR2, 0);
end;

procedure TfmLM2576Rev.edR1Change(Sender: TObject);
begin
  DoFieldChanged;
end;

procedure TfmLM2576Rev.edR1KeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9',chr(VK_BACK),chr(VK_DELETE)]) then Key := #0;
end;

procedure TfmLM2576Rev.FieldsChanged;
var r1,r2: single;
begin
  r1 := checkField(edR1);
  r2 := checkField(edR2);
  edResult.Text := Format('%.2f', [1.23*(1.0+(r2/r1))]);
end;

end.
